import MyComponent from "../classes/MyComponent.js";
import {generateElement} from "../functions/common.js";

export class DataCell extends MyComponent {
    constructor(address, config) {
        super();
        this.elem = generateElement({
            ...config,
            type: "span",
            display: "inline-block"
        });
        this.data = null;
        this.address = address ? address : "DataCell";
        this.setInnerText(this.address);
    }

    changeValue(innerText, callBack) {
        this.innerText = innerText;
        this.setInnerText(innerText);
        try {
            anime({
                targets: this.elem,
                rotateX: "+=360deg",
                complete: (anim)=>{
                    if (callBack){callBack();}
                }
            });
        } catch (e) {
            console.error("Error:DataCell.changeInnerText:", e);
        }
    }

    setInnerText(newInnerText){
        this.elem.innerText = newInnerText;
    }

}